package com.scwatch.core.web.back;

import com.scwatch.common.orm.LimitRequest;
import com.scwatch.common.orm.Limitable;
import com.scwatch.common.web.Servlets;
import com.scwatch.core.constant.Constants;
import com.scwatch.core.domain.*;
import com.scwatch.core.html.HtmlGenerator;
import com.scwatch.core.html.HtmlService;
import com.scwatch.core.service.*;
import com.scwatch.core.support.Backends;
import com.scwatch.core.support.Context;
import com.scwatch.ext.domain.ScheduleJob;
import com.scwatch.ext.service.ScheduleJobService;
import com.scwatch.ext.service.impl.JobTaskServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

import static com.scwatch.core.constant.Constants.MESSAGE;
import static com.scwatch.core.constant.Constants.SAVE_SUCCESS;

/**
 *  快讯/重磅新闻
 *
 * @author gujianlin
 *
 */
@Controller
@RequestMapping("/core/flash_big")
public class FlashBigNewController {
    private static final Logger logger = LoggerFactory.getLogger(FlashBigNewController.class);

    public static final int INCLUDE_CHILDREN = 0;
    public static final int INCLUDE_MULTI = 1;
    public static final int MAIN_NODE = 2;


    /**
     * 滚动资讯栏查询
     * @param ids 栏目
     * @param connInfoid
     * @param title 重磅标题
     * @param tab 面板（快讯或重磅）
     * @param queryNodeId 栏目
     * @param queryNodeType
     * @param queryInfoPermType
     * @param queryStatus
     * @param request
     * @param ra
     * @param modelMap
     * @return 结果页面
     */
//    @RequiresPermissions("core:flash_big:list")
    @RequestMapping("flash_big_list.do")
    public String flash_big_list(Integer[] ids,Integer connInfoid,String title,String tab,
                       Integer queryNodeId, Integer queryNodeType,
                       Integer queryInfoPermType, String queryStatus, HttpServletRequest request, RedirectAttributes ra,
                       org.springframework.ui.Model modelMap) {
        Site site = Context.getCurrentSite();
        User user = Context.getCurrentUser();
//        validateIds(ids, site.getId());

        Integer [] scrollIds=getNodeIdsByFlag(Constants.MODEL_FLAG_SCROLLINFO,site,user);
        if(scrollIds!=null && scrollIds.length>0 && queryNodeId==null){
            queryNodeId=scrollIds[0];
        }
        Integer [] bigNewIds=getNodeIdsByFlag(Constants.MODEL_FLAG_BIGNEWS,site,user);
        Integer [] flasNewIds=getNodeIdsByFlag(Constants.MODEL_FLAG_NEWSFLASH,site,user);
        Node bigNode=null;
        Node flashNode=null;
        if(bigNewIds!=null && flasNewIds!=null && bigNewIds.length>0 && flasNewIds.length>0){
            bigNode=nodeQuery.get(bigNewIds[0]);
            flashNode=nodeQuery.get(flasNewIds[0]);

        }
        List<ScheduleJob>  joblist=scheduleJobMapper.finByClassAndMethod("com.scwatch.ext.collect.CollectorImpl","addFlashNew");

        if(joblist!=null && joblist.size()>0){
            modelMap.addAttribute("job",joblist.get(0));
        }
        Sort defSort = new Sort(Sort.Direction.DESC, "priority","publishDate");
        Limitable limitable = new LimitRequest(null,1, defSort);
        List<Info> bigNewInfos =infoQuery.findList(null,bigNewIds, null,
                null, null,new Integer[]{site.getId()},null,null, null,
                null,null, null, null, null,
                null, null, null, null, null,
                null, null, null,new String[]{"A"},null, null,
                null, null, null, null, null, null, limitable,null);

        Info connInfo=null;
        if(bigNewInfos!=null && bigNewInfos.size()>0){
            connInfo=bigNewInfos.get(0).getRefInfo();
            title=bigNewInfos.get(0).getTitle();
        }
        modelMap.addAttribute("queryNodeId", queryNodeId);
        modelMap.addAttribute("tab", tab);
        modelMap.addAttribute("connInfo", connInfo);
        modelMap.addAttribute("title",title);
        return "core/flash_big_news/scrollinfo";
    }

    /**
     * 发布快讯
     * @param ids
     * @param infoId
     * @param orderId
     * @param targetNodeId
     * @param tab 面板（快讯或重磅）
     * @param queryNodeId
     * @param queryNodeType
     * @param returnUrl
     * @param cronExpression
     * @param queryInfoPermType
     * @param queryStatus
     * @param request
     * @param ra
     * @return 结果页面
     */
//    @RequiresPermissions("core:flash_new:save")
    @RequestMapping("flashNewSave.do")
    public String flashNewSave(Integer[] ids,Integer infoId,Integer orderId,Integer targetNodeId,String tab,
                               Integer queryNodeId, Integer queryNodeType,String returnUrl,String cronExpression,
                               Integer queryInfoPermType, String queryStatus, HttpServletRequest request, RedirectAttributes ra) {
        Site site = Context.getCurrentSite();
        User user = Context.getCurrentUser();
        ids=new Integer[1];
        ids[0]=infoId;
//        validateIds(ids, site.getId());

//        infoService.updateInfoRef(ids,targetNodeId,orderId);

        Integer [] targetIds=getNodeIdsByFlag(Constants.MODEL_FLAG_NEWSFLASH,site,user);


        List<ScheduleJob>  joblist=scheduleJobMapper.finByClassAndMethod("com.scwatch.ext.collect.CollectorImpl","addFlashNew");
        ScheduleJob job=null;
        if(joblist!=null && joblist.size()>0){
            job=joblist.get(0);
        }

        //修改滚动资讯下发布快讯还是重磅新闻
        if(targetIds!=null && targetIds.length>0){

            nodeService.updatePublish(targetIds[0],"0");
        }

        Integer[] bigNodeIds=getNodeIdsByFlag(Constants.MODEL_FLAG_BIGNEWS,site,user);
        if(bigNodeIds!=null && bigNodeIds.length>0){
            nodeService.updatePublish(bigNodeIds[0],"1");
        }

        job.setCronExpression(cronExpression);

        try {
            //恢复job
            jobTaskService.updateCron(job.getId(),cronExpression);
            job.setIsRestore(1);
            job.setUser(user);
            job.setUpdateTime(new Date());//更新时间
            jobTaskService.resumeJob(job);
            scheduleJobMapper.insert(job);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }

//        if(targetIds!=null && targetIds.length>0){
////            Node parentNode=nodeQuery.get(targetIds[0]);
////            htmlService.makeNode(parentNode.getId());
//            htmlService.makeNode(targetIds[0]);
//        }
//        String ip = Servlets.getRemoteAddr(request);
//        for (Integer id : ids) {
//            Info bean=infoQuery.get(id);
//            logService.operation("core:info:focusRefInfo", bean.getTitle(), null, bean.getId(), ip, user.getId(), site.getId());
//            logger.info("{} focusRefInfo Info, title={}.", bean.getTitle(),user.getId());
//
//        }
        ra.addAttribute("queryNodeId", targetIds[0]);
//        ra.addAttribute("orderId", orderId);
//        ra.addAttribute("queryNodeType", queryNodeType);
//        ra.addAttribute("queryInfoPermType", queryInfoPermType);
//        ra.addAttribute("queryStatus", queryStatus);
//        ra.addFlashAttribute(MESSAGE, OPERATION_SUCCESS);
//        ra.addAttribute("returnUrl",returnUrl );
//        ra.addAttribute("showInfoId", infoId);
        ra.addAttribute("tab", tab);
        return "redirect:flash_big_list.do";
    }

    private Integer[] getNodeIdsByFlag(String modelFlag, Site site,User user) {
        Integer [] nodeIds=null;
        Map<String,String[]> paramMap=new HashMap<String,String[]>();
        paramMap.put("EQ_flag",new String[]{modelFlag});
        List<Model> models=modelService.findList(site.getId(),null,paramMap,null);

        paramMap=new HashMap<String,String[]>();
        String[] idsStr;
        if(models!=null && models.size()>0){
            idsStr=new String[models.size()];
            for(int i=0;i<models.size();i++){
                idsStr[i]=models.get(i).getId().toString();
            }
            paramMap.put("EQ_nodeModel.id",idsStr);
        }
        Sort paramSort=new Sort(Sort.Direction.ASC, "treeNumber", "id");
        List<Node>  currentNodeList=nodeQuery.findList(site.getId(),null,
                null,null,true,
                paramMap, paramSort);
//        currentNodeList= user.getInfoPermList(site.getId(), currentNodeList);
        if(currentNodeList!=null){
            nodeIds=new Integer[currentNodeList.size()];
            for(int i=0;i<currentNodeList.size();i++){
                nodeIds[i]=(currentNodeList.get(i).getId());
            }
        }
        return  nodeIds;
    }

    /**
     * 重磅选择时新闻，查询
     * @param queryNodeId 栏目
     * @param queryNodeType
     * @param queryInfoPermType
     * @param queryStatus 状态
     * @param returnUrl 返回url
     * @param connInfoid
     * @param title 重磅标题
     * @param tab
     * @param pageable 分页对象
     * @param request
     * @param modelMap
     * @return
     */
//    @RequiresPermissions("core:current_hour:chooseinfolist")
    @RequestMapping("chooseinfolist.do")
    public String chooseinfolist(Integer queryNodeId, Integer queryNodeType, Integer queryInfoPermType, String queryStatus,
                                 String returnUrl,Integer connInfoid,String title,String tab,
                                 @PageableDefault(sort = {"publishDate", "id"}, direction = Sort.Direction.DESC) Pageable pageable,
                                 HttpServletRequest request, org.springframework.ui.Model modelMap) {
        queryNodeType = queryNodeType == null ? 0 : queryNodeType;
        Integer siteId = Context.getCurrentSiteId();
        Site site=Context.getCurrentSite();
        User user = Context.getCurrentUser();
        Integer[] nodeIds=getNodeIdsByFlag(Constants.MODEL_FLAG_NEWS,site,user);
        Integer nodeId = queryNodeId;
        if(nodeIds!=null && nodeIds.length>0){
            nodeId=nodeIds[0];
        }
        Integer mainNodeId = null;
        String treeNumber = null;
        Node queryNode = null;
        if (queryNodeId != null) {
            queryNode = nodeQuery.get(queryNodeId);
        }
        if (queryNode != null) {
            if (queryNodeType == INCLUDE_MULTI) {
                nodeId = queryNodeId;
            } else if (queryNodeType == MAIN_NODE) {
                mainNodeId = queryNodeId;
            } else {
                treeNumber = queryNode.getTreeNumber();
            }
        }
        Map<String, String[]> params = Servlets.getParamValuesMap(request, Constants.SEARCH_PREFIX);
        int infoPermType = user.getInfoPermType(siteId);
        if (queryInfoPermType != null && queryInfoPermType > infoPermType) {
            infoPermType = queryInfoPermType;
        }
        boolean allInfoPerm = user.getAllInfoPerm(siteId);

        //只查新闻类型的新闻
        Integer[] modelIds=null;
        Map<String,String[]> paramMap=new HashMap<String,String[]>();
        paramMap.put("EQ_flag",new String[]{Constants.MODEL_FLAG_DOC_NEWS});
        List<Model> modelList=modelService.findList(siteId,null,paramMap,null);
        if(modelList!=null && modelList.size()>0){
            modelIds=new Integer[modelList.size()];
            for(int i=0;i<modelList.size();i++){
                modelIds[i]=modelList.get(i).getId();
            }
        }

        Page<Info> pagedList = infoQuery.findAll(modelIds,siteId, mainNodeId,null, treeNumber, user.getId(), allInfoPerm,
                infoPermType, queryStatus, params, pageable,null);

        List<Attribute> attributeList = attributeService.findList(siteId);
        modelMap.addAttribute("pagedList", pagedList);
        modelMap.addAttribute("attributeList", attributeList);
        modelMap.addAttribute("queryNodeId", queryNodeId);
        modelMap.addAttribute("queryNodeType", queryNodeType);
        modelMap.addAttribute("queryInfoPermType", queryInfoPermType);
        modelMap.addAttribute("queryStatus", queryStatus);
        modelMap.addAttribute("node",queryNode);
        modelMap.addAttribute("returnUrl",returnUrl);
        modelMap.addAttribute("connInfoid",connInfoid);
        modelMap.addAttribute("title",title);
        modelMap.addAttribute("tab",tab);
        return returnUrl;
    }

    /**
     * 查询重磅新闻
     * @param ids
     * @param connInfoid 重磅新闻id
     * @param title 标题
     * @param tab 面板标记
     * @param queryNodeId 栏目
     * @param queryNodeType
     * @param queryInfoPermType
     * @param queryStatus
     * @param request
     * @param ra
     * @param modelMap
     * @return 结果页面
     */
//    @RequiresPermissions("core:flash_new:list")
    @RequestMapping("list.do")
    public String list(Integer[] ids,Integer connInfoid,String title,String tab,
                       Integer queryNodeId, Integer queryNodeType,
                       Integer queryInfoPermType, String queryStatus, HttpServletRequest request, RedirectAttributes ra,
                       org.springframework.ui.Model modelMap) {
        Info connInfo=null;
        if(connInfoid!=null){
            connInfo=infoQuery.get(connInfoid);
            title=connInfo.getTitle();
        }
        modelMap.addAttribute("queryNodeId", queryNodeId);
        modelMap.addAttribute("queryNodeType", queryNodeType);
        modelMap.addAttribute("queryInfoPermType", queryInfoPermType);
        modelMap.addAttribute("queryStatus", queryStatus);
        modelMap.addAttribute("connInfo", connInfo);
        modelMap.addAttribute("title", title);
        modelMap.addAttribute("tab", tab);

        return "core/flash_big_news/scrollinfo";
    }

    /**
     * 重磅新闻发布
     * @param bean
     * @param detail
     * @param nodeIds
     * @param specialIds
     * @param viewGroupIds
     * @param voteIds
     * @param viewOrgIds
     * @param attrIds
     * @param nodeId
     * @param tagKeywords
     * @param tab 面板标记
     * @param connInfoid 重磅新闻id
     * @param draft
     * @param imagesName
     * @param imagesText
     * @param imagesImage
     * @param filesName
     * @param filesFile
     * @param filesLength
     * @param redirect
     * @param queryNodeId
     * @param queryNodeType
     * @param queryInfoPermType
     * @param queryStatus
     * @param request
     * @param ra
     * @return 结果页面
     */
//    @RequiresPermissions("core:info:save")
    @RequestMapping("infosave.do")
    public String infosave(Info bean, InfoDetail detail, Integer[] nodeIds, Integer[] specialIds, Integer[] viewGroupIds,Integer[] voteIds,
                           Integer[] viewOrgIds, Integer[] attrIds, Integer nodeId, String tagKeywords,String tab,Integer connInfoid,
                           @RequestParam(defaultValue = "false") boolean draft, String[] imagesName, String[] imagesText,
                           String[] imagesImage, String[] filesName, String[] filesFile, Long[] filesLength, String redirect,
                           Integer queryNodeId, Integer queryNodeType, Integer queryInfoPermType, String queryStatus,
                           HttpServletRequest request, RedirectAttributes ra) {

        Site site=Context.getCurrentSite();
        User user=Context.getCurrentUser();
        Integer siteId = site.getId();
        Integer userId = user.getId();

        //重磅新闻参数
        Integer[] ids=getNodeIdsByFlag(Constants.MODEL_FLAG_BIGNEWS,site,user);
        nodeId=ids[0];
        if(connInfoid!=null){
            Info connInfo=infoQuery.get(connInfoid);
            bean.setRefInfo(connInfo);
        }
        //处理标题中的 单双引号
        String paramTitle=detail.getTitle();
        if(paramTitle!=null){
            paramTitle=paramTitle.replaceAll("\"(.*?)\"","“$1”").replaceAll("'(.*?)'","‘$1’");
            detail.setTitle(paramTitle);
        }


        Map<String, String> customs = Servlets.getParamMap(request, "customs_");
        Map<String, String> clobs = Servlets.getParamMap(request, "clobs_");
        if (StringUtils.isBlank(detail.getMetaDescription())) {
            String title = detail.getTitle();
            detail.setMetaDescription(Info.getDescription(clobs, title));
        }
        String[] tagNames = splitTagKeywords(tagKeywords);
        Map<String, String> attrImages = Servlets.getParamMap(request, "attrImages_");
        for (Map.Entry<String, String> entry : attrImages.entrySet()) {
            entry.setValue(StringUtils.trimToNull(entry.getValue()));
        }
        List<InfoImage> images = new ArrayList<InfoImage>();
        if (imagesName != null) {
            InfoImage infoImage;
            for (int i = 0, len = imagesName.length; i < len; i++) {
                if (StringUtils.isNotBlank(imagesName[i]) || StringUtils.isNotBlank(imagesText[i])
                        || StringUtils.isNotBlank(imagesImage[i])) {
                    infoImage = new InfoImage(imagesName[i], imagesText[i], imagesImage[i]);
                    images.add(infoImage);
                }
            }
        }
        List<InfoFile> files = new ArrayList<InfoFile>();
        if (filesName != null) {
            InfoFile infoFile;
            for (int i = 0, len = filesFile.length; i < len; i++) {
                if (StringUtils.isNotBlank(filesName[i]) && StringUtils.isNotBlank(filesFile[i])) {
                    infoFile = new InfoFile(filesName[i], filesFile[i], filesLength[i]);
                    files.add(infoFile);
                }
            }
        }
        if(specialIds!=null && specialIds.length==1){
            if(specialIds[0]==null){
                specialIds=null;
            }
        }
        if(voteIds!=null && voteIds.length==1){
            if(voteIds[0]==null){
                voteIds=null;
            }
        }
        String status = draft ? Info.DRAFT : null;
        bean.setStatus("A"); //正常，已发布
        Info result=infoService.save(bean, detail, nodeIds, specialIds, viewGroupIds, viewOrgIds,voteIds,customs, clobs, images, files,
                attrIds, attrImages, tagNames, nodeId, userId, status, siteId);

        //修改滚动资讯下发布快讯还是重磅新闻
        nodeService.updatePublish(nodeId,"0");
        Integer[] newsFlashNodeIds=getNodeIdsByFlag(Constants.MODEL_FLAG_NEWSFLASH,site,user);
        if(newsFlashNodeIds!=null && newsFlashNodeIds.length>0){
            nodeService.updatePublish(newsFlashNodeIds[0],"1");
        }

        if(bean!=null && bean.getNode()!=null && bean.getNode().getId()!=null){
            htmlGenerator.makeNode(site.getId(), bean.getNode().getId(),"滚动资讯栏", true, user.getId(),null);
        }


        List<ScheduleJob>  joblist=scheduleJobMapper.finByClassAndMethod("com.scwatch.ext.collect.CollectorImpl","addFlashNew");
        ScheduleJob job=null;
        if(joblist!=null && joblist.size()>0){
            job=joblist.get(0);
            try {
                job.setIsRestore(2);
                job.setUser(user);
                job.setUpdateTime(new Date());//更新时间
                jobTaskService.pauseJob(job);
            } catch (SchedulerException e) {
                e.printStackTrace();
            }
        }

        String ip = Servlets.getRemoteAddr(request);
        logService.operation("opr.info.add", bean.getTitle(), null, bean.getId(), ip, userId, siteId);
        logger.info("save Info, title={}.", bean.getTitle());
        ra.addAttribute("queryNodeId", nodeId);
        ra.addAttribute("queryNodeType", queryNodeType);
        ra.addAttribute("queryInfoPermType", queryInfoPermType);
        ra.addAttribute("queryStatus", queryStatus);
        ra.addFlashAttribute(MESSAGE, SAVE_SUCCESS);
        ra.addAttribute("tab",tab);
//        if (Constants.REDIRECT_LIST.equals(redirect)) {
//            ra.addAttribute("returnUrl","core/current_hour/currentnews_list");
//            return "redirect:list.do";
//        } else if (Constants.REDIRECT_CREATE.equals(redirect)) {
//            return "redirect:infocreate.do";
//        } else {
//            ra.addAttribute("id", bean.getId());
//            return "redirect:infoedit.do";
//        }
        return "redirect:flash_big_list.do";
    }

    /**
     * 取消重磅发布
     * @param tab 面板标记
     * @param request 请求对象
     * @param ra
     * @return 结果页面
     */
    @RequiresPermissions("core:flash_big:cancelBigPublish")
    @RequestMapping("cancelBigPublish.do")
    public String cancelBigPublish(String tab,
                           HttpServletRequest request, RedirectAttributes ra) {

        Site site=Context.getCurrentSite();
        User user=Context.getCurrentUser();
        Integer siteId = site.getId();
        Integer userId = user.getId();

        //重磅新闻参数
        Integer[] ids=getNodeIdsByFlag(Constants.MODEL_FLAG_BIGNEWS,site,user);

        Integer nodeId=ids[0];
        //取消滚动资讯下重磅新闻发布
        nodeService.updatePublish(nodeId,"1");

        htmlGenerator.makeNode(site.getId(),nodeId,"重磅新闻", false, user.getId(),null);
        String ip = Servlets.getRemoteAddr(request);
        logService.operation("opr.flash_big.cancelBigPublish","重磅新闻", null,nodeId, ip, userId, siteId);
        logger.info("cancelBigPublish nodeId={}.",nodeId);
        ra.addAttribute("queryNodeId", nodeId);
        ra.addFlashAttribute(MESSAGE, SAVE_SUCCESS);
        ra.addAttribute("tab",tab);
        return "redirect:flash_big_list.do";
    }

    @ModelAttribute
    public void preloadNodeBean(@RequestParam(required = false) Integer oid, org.springframework.ui.Model modelMap) {
        if (oid != null) {
            Node bean = nodeQuery.get(oid);
            if (bean != null) {
                modelMap.addAttribute("bean", bean);
                NodeDetail detail = bean.getDetail();
                if (detail == null) {
                    detail = new NodeDetail();
                    detail.setId(oid);
                    detail.setNode(bean);
                }
                modelMap.addAttribute("detail", detail);
            }
        }
    }

    @ModelAttribute
    public void preloadInfoBean(@RequestParam(required = false) Integer oid, org.springframework.ui.Model modelMap) {
        if (oid != null) {
            Info bean = infoQuery.get(oid);
            if (bean != null) {
                modelMap.addAttribute("bean", bean);
                InfoDetail detail = bean.getDetail();
                if (detail == null) {
                    detail = new InfoDetail();
                    detail.setId(oid);
                    detail.setInfo(bean);
                }
                modelMap.addAttribute("detail", detail);
            }
        }
    }

    private void validateIds(Integer[] ids, Integer siteId) {
        for (Integer id : ids) {
            Backends.validateDataInSite(nodeQuery.get(id), siteId);
        }
    }

    private Integer[] getInfoPermIds(Integer siteId, Integer parentId) {
        Collection<Role> roles = null;
        if (parentId != null) {
            Node node = nodeQuery.get(parentId);
            if (node != null) {
                roles = node.getInfoPerms();
            }
        }
        if (roles == null) {
            roles = roleService.findList(siteId);
        }
        int len = roles.size();
        Integer[] ids = new Integer[len];
        int i = 0;
        for (Role role : roles) {
            ids[i++] = role.getId();
        }
        return ids;
    }

    private Integer[] getNodePermIds(Integer siteId, Integer parentId) {
        Collection<Role> roles = null;
        if (parentId != null) {
            Node node = nodeQuery.get(parentId);
            if (node != null) {
                roles = node.getNodePerms();
            }
        }
        if (roles == null) {
            roles = roleService.findList(siteId);
        }
        int len = roles.size();
        Integer[] ids = new Integer[len];
        int i = 0;
        for (Role role : roles) {
            ids[i++] = role.getId();
        }
        return ids;
    }

    private Integer[] getViewGroupIds(Integer siteId, Integer parentId) {
        Collection<MemberGroup> groups = null;
        if (parentId != null) {
            Node node = nodeQuery.get(parentId);
            if (node != null) {
                groups = node.getViewGroups();
            }
        }
        if (groups == null) {
            groups = memberGroupService.findList();
        }
        int len = groups.size();
        Integer[] ids = new Integer[len];
        int i = 0;
        for (MemberGroup group : groups) {
            ids[i++] = group.getId();
        }
        return ids;
    }

    private Integer[] getContriGroupIds(Integer siteId, Integer parentId) {
        Collection<MemberGroup> groups = null;
        if (parentId != null) {
            Node node = nodeQuery.get(parentId);
            if (node != null) {
                groups = node.getContriGroups();
            }
        }
        if (groups == null) {
            groups = memberGroupService.findList();
        }
        int len = groups.size();
        Integer[] ids = new Integer[len];
        int i = 0;
        for (MemberGroup group : groups) {
            ids[i++] = group.getId();
        }
        return ids;
    }

    private Integer[] getCommentGroupIds(Integer siteId, Integer parentId) {
        Collection<MemberGroup> groups = null;
        if (parentId != null) {
            Node node = nodeQuery.get(parentId);
            if (node != null) {
                groups = node.getCommentGroups();
            }
        }
        if (groups == null) {
            groups = memberGroupService.findList();
        }
        int len = groups.size();
        Integer[] ids = new Integer[len];
        int i = 0;
        for (MemberGroup group : groups) {
            ids[i++] = group.getId();
        }
        return ids;
    }
    private String[] splitTagKeywords(String tagKeywords) {
        String split = Constants.TAG_KEYWORDS_SPLIT;
        if (StringUtils.isNotBlank(split)) {
            for (int i = 0, len = split.length(); i < len; i++) {
                tagKeywords = StringUtils.replace(tagKeywords, String.valueOf(split.charAt(i)), ",");
            }
        }
        return StringUtils.split(tagKeywords, ',');
    }

    @Autowired
    private OperationLogService logService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private MemberGroupService memberGroupService;
    @Autowired
    private WorkflowService workflowService;
    @Autowired
    private ModelService modelService;
    @Autowired
    private NodeService nodeService;
    @Autowired
    private NodeQueryService nodeQuery;
    @Autowired
    private AttributeService attributeService;
    @Autowired
    private InfoQueryService infoQuery;
    @Autowired
    private InfoService infoService;
    @Autowired
    private HtmlService htmlService;
    @Autowired
    private InfoNodeService infoNodeService;
    @Autowired
    private  FlashBigNewService flashBigNewService;
    @Autowired
    private JobTaskServiceImpl jobTaskService;
    @Autowired
    private ScheduleJobService scheduleJobMapper;
    @Autowired
    private HtmlGenerator htmlGenerator;


}
